/**
 * 详情对话框
 */
var MainInfoInfoDlg = {
    data: {
        id: "",
        isDel: "",
        relXqId: "",
        wxXm: "",
        tswxXm: "",
        sgfa: "",
        gcys: "",
        ftl: "",
        showDay: "",
        startDate: "",
        state: "",
        createPerson: "",
        createDate: "",
        updatePerson: "",
        updateDate: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate', 'upload', 'formSelects', 'layer'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;


    $.ajax(Feng.ctxPath + '/xqInfo/listAll', {
        async: false,
        success: function (res) {
            // console.log(res)
            $("#relXqId").empty();
            $("#relXqId").append("<option value=''>请选择小区</option>");
            for (let i = 0; i < res.length; i++) {
                $("#relXqId").append(new Option(res[i].xqName, res[i].id))
            }
            //重新渲染
            form.render("select");
        }
    })


    //渲染时间选择框
    var laydate = layui.laydate;
    laydate.render({
        elem: '#startDate' //指定元素
    });


    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/mainInfo/publicityInfo?main_id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    // console.log(result)
    form.val('mainInfoForm', result.data.publicityInfo[0]);
    if (result.data.publicityInfo[0].ftl == 1) {
        $("#ftl").val("100")
    } else {
        $("#ftl").val(Number(result.data.publicityInfo[0].ftl * 100).toFixed(1))
    }
    $("#userNumber").val(result.data.publicityInfo[0].vote_all_num)
    $("input:checkbox[value='1']").prop("checked", false)
    if (result.data.publicityInfo[0].tswx_xm != null && result.data.publicityInfo[0].tswx_xm != "") {
        var specialMaintenanceArray = result.data.publicityInfo[0].tswx_xm.split(",")
        for (let i = 0; i < specialMaintenanceArray.length; i++) {
            $("input:checkbox[value='" + specialMaintenanceArray[i] + "']").prop("checked", true)
        }
        form.render("checkbox")
    }

    if (result.data.fileList != null && result.data.fileList != "") {
        var pictrueArr = new Array();
        pictrueArr = JSON.parse(result.data.fileList);
        // console.log(pictrueArr)
        for (let i = 0; i < pictrueArr.length; i++) {
            $("#preLookPicture").append('<img id="_' + i + '" style="width: 150px; margin:10px;cursor:pointer;" src="' + pictrueArr[i] + '">')

            //某图片放大预览
            $("#_" + i).bind('click', function () {
                var width = $("#_" + i).width();
                var height = $("#_" + i).height();
                var scaleWH = width / height;
                var bigH = 600;
                var bigW = scaleWH * bigH;
                if (bigW > 900) {
                    bigW = 900;
                    bigH = bigW / scaleWH;
                }

                // 放大预览图片
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 1,
                    shadeClose: true,
                    area: [bigW + 'px', bigH + 'px'], //宽高
                    content: "<img width='" + bigW + "' height='" + bigH + "' src=" + pictrueArr[i] + " />"
                });
            });
        }
    }


    $('#cancel').click(function () {
        window.location.href = Feng.ctxPath + '/mainInfo'
    });
});